﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.ComponentModel;

namespace poco
{
    public class Contact
    {
        [JsonProperty(PropertyName="id")]
        public string ID { get; set; }

        [JsonProperty(PropertyName="displayName")]
        public string DisplayName { get; set; }

        [JsonProperty(PropertyName = "name", NullValueHandling = NullValueHandling.Ignore)]
        public Name Name { get; set; }

        [JsonProperty(PropertyName = "nickName", NullValueHandling = NullValueHandling.Ignore)]
        public string NickName { get; set; }

        [JsonProperty(PropertyName = "published", NullValueHandling = NullValueHandling.Ignore)]
        [JsonConverter(typeof(IsoDateTimeConverter))]
        public DateTime? Published { get; set; }

        [JsonProperty(PropertyName = "updated", NullValueHandling = NullValueHandling.Ignore)]
        [JsonConverter(typeof(IsoDateTimeConverter))]
        public DateTime? Updated { get; set; }

        [JsonProperty(PropertyName = "birthday", NullValueHandling = NullValueHandling.Ignore)]
        public DateTime? Birthday { get; set; }

        [JsonProperty(PropertyName = "anniversary", NullValueHandling = NullValueHandling.Ignore)]
        public DateTime? Anniversary { get; set; }

        [JsonProperty(PropertyName = "gender", NullValueHandling = NullValueHandling.Ignore)]
        public string Gender { get; set; }

        [JsonProperty(PropertyName = "note", NullValueHandling = NullValueHandling.Ignore)]
        public string Note { get; set; }

        [JsonProperty(PropertyName = "preferredUsername", NullValueHandling = NullValueHandling.Ignore)]
        public string PreferredUsername { get; set; }

        [JsonProperty(PropertyName = "utcOffset", NullValueHandling = NullValueHandling.Ignore)]
        public string UtcOffset { get; set; }

        [JsonProperty(PropertyName = "connected")]
        [DefaultValue(false)]
        public bool Connected{ get; set; }
        
        [JsonProperty(PropertyName = "email", NullValueHandling = NullValueHandling.Ignore)]
        public Emails Email {get; set;}

        [JsonProperty(PropertyName = "phoneNumber", NullValueHandling = NullValueHandling.Ignore)]
        public PhoneNumbers PhoneNumber { get; set; }

        public override bool Equals(object obj)
        {
            if (obj == null) return false;
            if (obj.GetType() != this.GetType()) return false;
            Contact other = (Contact)obj;

            if (!Object.Equals(this.ID, other.ID)) return false;
            if (!Object.Equals(this.DisplayName, other.DisplayName)) return false;
            if (!Object.Equals(this.Name, other.Name)) return false;

            if (!Object.Equals(this.NickName, other.NickName)) return false;
            if (!Object.Equals(this.Published, other.Published)) return false;
            if (!Object.Equals(this.Updated, other.Updated)) return false;
            if (!Object.Equals(this.Birthday, other.Birthday)) return false;
            if (!Object.Equals(this.Anniversary, other.Anniversary)) return false;
            if (!Object.Equals(this.Gender, other.Gender)) return false;
            if (!Object.Equals(this.Note, other.Note)) return false;
            if (!Object.Equals(this.PreferredUsername, other.PreferredUsername)) return false;
            if (!Object.Equals(this.UtcOffset, other.UtcOffset)) return false;
            if (!Object.Equals(this.Connected, other.Connected)) return false;

            if (!Object.Equals(this.Email, other.Email)) return false;

            return true;
        }

        public override int GetHashCode()
        {
            return ID.GetHashCode();
        }
    }
}
